{extend name="base"/}
{block name="title"}命令模式{/block}
{block name="resource"}

{/block}
{block name="body"}
<button id="button1">点击按钮1</button>
<button id="button2">点击按钮2</button>
<button id="button3">点击按钮3</button>
{/block}
{block name="script"}
<script>
    var button1 = document.getElementById( 'button1' );
    var button2 = document.getElementById( 'button2' );
    var button3 = document.getElementById( 'button3' );
    var setCommand = function(button, func){
        button.onclick = function(){
            func();
        };
    }

    var menuBar = {
        refresh : function(){
            console.log('refresh');
        }
    }

    var subMenu = {
        add : function(){
            console.log('add');
        },
        del : function(){
            console.log('del');
        }
    }

    setCommand(button1, menuBar.refresh);
    setCommand(button2, subMenu.add);
    setCommand(button3, subMenu.del);
</script>
{/block}

